﻿using System.Collections.Generic;
using System.Linq;
using Turquoise.Business.Abstract;
using Turquoise.Caching.Entities;
using Turquoise.DataAccess.Abstract;
using Turquoise.Entities.Data;

namespace Turquoise.Business
{
    public class LanguageManager : ILanguageService
    {
        private readonly IRepository<Language> _repository;

        public LanguageManager(IRepository<Language> repository)
        {
            _repository = repository;
        }

        [TurquoiseCache]
        public List<Language> GetAll()
        {
            return _repository.DbSet().Where(e => e.IsApproved).Select(t => new {t.Id, t.LanguageCode, t.LanguageName}).ToList().Select(item => new Language
            {
                Id = item.Id,
                LanguageCode = item.LanguageCode,
                LanguageName = item.LanguageName
            }).ToList();
        }

        [TurquoiseCache]
        public string GetCodeById(int id)
        {
            return _repository.DbSet().Where(e => e.Id == id).Select(t => t.LanguageCode).FirstOrDefault();
        }
    }
}
